package com.maxd.modules.selfshop.merchants.respository;


import com.maxd.modules.selfshop.merchants.entity.SelfMerchantApply;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface SelfMerchantApplyJpaRepository extends JpaRepository<SelfMerchantApply, Long> {

    //条件查询带分页
    Page<SelfMerchantApply> findAll(Specification<SelfMerchantApply> specification, Pageable pageable);

    //条件查询
    List<SelfMerchantApply> findAll(Specification<SelfMerchantApply> specification);

    //商户名称
    @Query(value = "from SelfMerchantApply s where s.storeName=:storeName")
    SelfMerchantApply checkStoreName(@Param("storeName") String storeName);

    //手机号
    @Query(value = "from SelfMerchantApply s where s.legalPhone=:legalPhone")
    SelfMerchantApply checkLegalPhone(@Param("legalPhone") String legalPhone);

    @Modifying
    @Transactional
    @Query(value = "update SelfMerchantApply s set s.money=:money where s.id=:id")
    Integer updateMoneyAdd(@Param("money") BigDecimal money, @Param("id") Long id);

    @Modifying
    @Transactional
    @Query(value = "update SelfMerchantApply s set s.money=:money where s.id=:id")
    Integer updateMoneyLess(@Param("money") BigDecimal money,@Param("id") Long id);

}
